<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model backend\modules\home\models\MhArticle */

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => '文章列表', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<style type="text/css">
    th{min-width:120px;}
</style>
<div class="mh-article-view">

    <p>
        <?= Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
        <?= Html::a('删除', ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            [
                'format' => 'raw',
                'attribute' => 'cid',
                'value' => function($model) {
                    if($model->cid == 0){
                        return '<span class="btn btn-xs btn-danger">无</span>';
                    } else {
                        return $model->cid;
                    }
                },
            ],
            [
                'format' => 'raw',
                'attribute' => 'type',
                'value' => function($model) {
                    if($model->type == 0){
                        return '<span class="btn btn-xs btn-info">单页面</span>';
                    } else {
                        return '<span class="btn btn-xs btn-info">分类文章</span>';
                    }
                },
            ],
            'title',
            'summary',
            'author',
            'read',
            'is_hot',
            'is_recommend',
            [
                'format' => 'raw',
                'attribute' => 'tag',
                'value' => function($model) {
                    if($model->tag){
                        return $model->tag;
                    } else {
                        return '';
                    }
                },
            ],
            'order',
            // 'image_path',
            'url:url',
            'content:ntext',
            [
                'format' => 'raw',
                'attribute' => 'status',
                'value' => function($model) {
                    if($model->status == 0){
                        return '<span class="btn btn-xs btn-danger">未发布</span>';
                    } elseif ($model->status == 1) {
                       return '<span class="btn btn-xs btn-primary">已发布</span>';
                    } else {
                        return '';
                    }

                },
            ],
            [
                'format' => 'raw',
                'attribute' => 'publish_date',
                'value' => function($model) {
                    if($model->publish_date){
                        return $model->publish_date;
                    }
                },
            ],
            [
                'format' => 'raw',
                'attribute' => 'create_time',
                'value' => function($model) {
                    return date('Y-m-d H:i:s', $model->create_time);
                },
            ],
        ],
    ]) ?>

</div>
